package org.flowers.unbeaten.util;

import com.github.pagehelper.Page;

import java.util.List;

/**
 * @description 分页工具类
 * @author RyanWang
 * @date 2021-08-04 09:42:17
 * @version 1.0
 */
public class PageUtils {

    private PageUtils() {
    }

    public static <T> PageVo<T> getPageVo(List<T> list) {
        PageVo<T> vo = new PageVo<>();
        if (list instanceof Page) {
            Page<T> page = (Page<T>) list;
            vo.setTotalRows(page.getTotal());
            vo.setTotalPages(page.getPages());
            vo.setPageNumber(page.getPageNum());
            vo.setCurrentPageSize(page.size());
            vo.setPageSize(page.size());
            vo.setList(page.getResult());
        }
        return vo;
    }

}
